package com.smart.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.common.vo.ResponseResult;
import com.smart.product.common.query.ProductQuery;
import com.smart.product.service.ProductService;
import com.smart.product.common.vo.GoodsDetailVO;
import com.smart.product.common.vo.ProductDetailVo;
import com.smart.product.common.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author zhangwei
 */
@Api("前台商品API")
@RestController
@RequestMapping("/product")
public class ProductController {
    @Resource
    private ProductService productService;

    @ApiOperation("通过商品ID查询商品详情")
    @GetMapping("/{id}")
    public ResponseResult<ProductDetailVo> detail(@PathVariable("id") Long productId) {
        return ResponseResult.success(productService.getProductDetail(productId));
    }

    @ApiOperation(value = "搜索商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", example = "1", paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "size", value = "每页数量", example = "10", paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "keyword", value = "关键字", example = "华为P50", paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "categoryId", value = "商品类目", example = "1", paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "sort",
                    value = "排序字段:0->默认；1->按新品；2->按销量；3->价格从低到高；4->价格从高到低",
                    example = "price", allowableValues = "0,1,2,3,4", paramType = "query", dataType = "integer", dataTypeClass = Integer.class)
    })

    @GetMapping("/search")
    public ResponseResult<IPage<ProductVo>> search(@Valid ProductQuery productQuery) {
        IPage<ProductVo> productPage = productService.search(productQuery);
        return ResponseResult.success(productPage);
    }

    /**
     * @param skuId
     * @return
     */
    @ApiOperation(value = "商品详情")
    @ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long")
    @GetMapping("/sku/{skuId}")
    public ResponseResult<GoodsDetailVO> detailBySkuId(@PathVariable Long skuId) {
        return null;
    }
}
